package JZOffer;
import java.util.ArrayList;

public class _3 {
    class Solution{
        public ArrayList<Integer> printListFromTaiToHead(ListNode listNode) {
            ArrayList<Integer> res = new ArrayList<Integer>();
            ListNode temp = listNode;
            while (temp != null) {
                res.add(0,temp.val);
                temp = temp.next;
            }
            return res;
        }
    }

    Solution getSolution() {
        return new Solution();
    }

    public static void main(String args[]) {
        _3 c = new _3();
        _3.Solution s = c.getSolution();
        ListNode L1 = new ListNode(3);
        ListNode L2 = new ListNode(4);
        ListNode L3 = new ListNode(5);
        ListNode L4 = new ListNode(6);
        ListNode L5 = new ListNode(7);
        L1.next = L2;
        L2.next = L3;
        L3.next = L4;
        L4.next = L5;
        ArrayList<Integer> r = s.printListFromTaiToHead(L1);
        for (Integer i : r) {
            System.out.println(i);
        }
    }
}
